package ListNode;
import java.util.ArrayDeque;
import java.util.Deque;

class ListNode1{
    int val;
    ListNode1 next;
    ListNode1(int x){
        val=x;
    }
}

public class Offer06 {
    public int[] reversePrint(ListNode.ListNode1 head){
        Deque<Integer> stack = new ArrayDeque<>();
        while(head!=null){
            stack.push(head.val);
            head=head.next;
        }
        int [] res = new int[stack.size()];
        for (int i=0;i<res.length;i++){
                 res[i]=stack.pop();//pop是栈结构的实现类的方法，表示返回栈顶的元素，同时该元素从栈中删除
        }

        return res;
    }

}
